package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.TeacherCampus;
import com.ruoyi.system.service.ITeacherCampusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 教师校区表Controller
 * 
 * @author bearzz
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/campus")
public class TeacherCampusController extends BaseController
{
    @Autowired
    private ITeacherCampusService teacherCampusService;

    /**
     * 查询教师校区表列表
     */
    @RequiresPermissions("teacher:campus:list")
    @GetMapping("/list")
    public TableDataInfo list(TeacherCampus teacherCampus)
    {
        startPage();
        List<TeacherCampus> list = teacherCampusService.selectTeacherCampusList(teacherCampus);
        return getDataTable(list);
    }

    /**
     * 导出教师校区表列表
     */
    @RequiresPermissions("teacher:campus:export")
    @Log(title = "教师校区表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeacherCampus teacherCampus)
    {
        List<TeacherCampus> list = teacherCampusService.selectTeacherCampusList(teacherCampus);
        ExcelUtil<TeacherCampus> util = new ExcelUtil<TeacherCampus>(TeacherCampus.class);
        util.exportExcel(response, list, "教师校区表数据");
    }

    /**
     * 获取教师校区表详细信息
     */
    @RequiresPermissions("teacher:campus:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(teacherCampusService.selectTeacherCampusById(id));
    }

    /**
     * 新增教师校区表
     */
    @RequiresPermissions("teacher:campus:add")
    @Log(title = "教师校区表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeacherCampus teacherCampus)
    {
        return toAjax(teacherCampusService.insertTeacherCampus(teacherCampus));
    }

    /**
     * 修改教师校区表
     */
    @RequiresPermissions("teacher:campus:edit")
    @Log(title = "教师校区表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeacherCampus teacherCampus)
    {
        return toAjax(teacherCampusService.updateTeacherCampus(teacherCampus));
    }

    /**
     * 删除教师校区表
     */
    @RequiresPermissions("teacher:campus:remove")
    @Log(title = "教师校区表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teacherCampusService.deleteTeacherCampusByIds(ids));
    }
}
